#include "mutex.h"

namespace reldt {

Mutex::Mutex()
{
	pthread_mutexattr_t a;
	pthread_mutexattr_init(&a);
	pthread_mutexattr_settype(&a, PTHREAD_MUTEX_RECURSIVE);
    pthread_mutex_init(&m, &a);
}

Mutex::~Mutex()
{
    pthread_mutex_destroy(&m);
}

void Mutex::lock()
{
    pthread_mutex_lock(&m);
}

bool Mutex::trylock()
{
    return !(pthread_mutex_trylock(&m));
}

void Mutex::unlock()
{
    pthread_mutex_unlock(&m);
}

}
